// HealthService.java
package com.community.service;

import com.community.dao.HealthDao;
import com.community.dao.impl.HealthDaoImpl;
import com.community.model.HealthInfo;
import java.util.List;

public class HealthService {
    private final HealthDao healthDao = new HealthDaoImpl();

    public void submitHealthInfo(HealthInfo info) {
        validateHealthInfo(info);
        healthDao.insert(info);
    }

    public List<HealthInfo> getRecentHealthRecords(int limit) {
        if (limit <= 0) limit = 10;
        return healthDao.getRecent(limit);
    }

    private void validateHealthInfo(HealthInfo info) {
        if (info.getElderId() <= 0) {
            throw new IllegalArgumentException("老人ID无效");
        }
        if (info.getTemperature() < 35 || info.getTemperature() > 42) {
            throw new IllegalArgumentException("体温应在35℃-42℃之间");
        }
        if (info.getSymptoms() == null || info.getSymptoms().trim().isEmpty()) {
            throw new IllegalArgumentException("症状描述不能为空");
        }
    }
}